const app = getApp()
Component({
    properties: {
      endtime: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatetime()
        }
      },
        textColor:String,
        targetTime:Number,
        type:String
      },
    data: {
        styleType:'style1',
        fontSize:'11px',
        baseColor:'rgba(153,153,153,1)',
        bgColor:'#DE443A',
        endtime:0
    },

    lifetimes: {
      attached: function () {
              this.getCountDown();
       }
    },
    methods: {
      updatetime:function(){
        console.log('时间:'+this.data.endtime)
      },
      getCountDown:function(){
        var time = this.data.endtime;
        if(time <= 0){
            this.setData({
              endtime:0
            })
            return false;
        }else{
          this.setData({
            endtime:parseInt(time)-1
          })
        }
        setTimeout(this.getCountDown, 1000);
        this.countTime();
     },
      countTime(){
            var leftTime=this.data.endtime
             var d, h, m, s, ms;
             if (leftTime >= 0) {
               d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
               h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
               m = Math.floor(leftTime / 1000 / 60 % 60);
               s = Math.floor(leftTime / 1000 % 60);
               ms = Math.floor(leftTime % 1000);
               ms = ms < 100 ? "0" + ms : ms
               s = s < 10 ? "0" + s : s
               m = m < 10 ? "0" + m : m
               h = h < 10 ? "0" + h : h
               this.setData({
                 day: d,
                 hour:h, 
                 minus:m,
                 second:s
               })
             } 
          }
          
    }
});
